package com.dxj.controller;
import com.dxj.request.RolePageDTO;
import com.dxj.request.RolePermissionDTO;
import com.dxj.response.PageResultVo;
import com.dxj.response.R;
import com.dxj.response.RoleInfoVo;
import com.dxj.service.IRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author dxj
 * @Description 角色接口
 * @date 2024/7/30 22:00
 */
@RestController
@Api(tags = "角色模块")
@RequestMapping("/role")
public class RoleController {
    private static final Logger logger = LoggerFactory.getLogger(UserController.class);
    @Resource
    private IRoleService roleService;

    /**
     * 新增角色分配权限
     * @param rolePermissionDTO
     * @return
     */
    @PostMapping("/insert")
    @ApiOperation(value = "新增角色分配权限")
    public R insert(@RequestBody @Validated RolePermissionDTO rolePermissionDTO) {
        logger.info("新增角色分配权限入参:{}", rolePermissionDTO);
        return roleService.insertRole(rolePermissionDTO);
    }

    /**
     * 删除角色
     * @param id
     * @return
     */
    @GetMapping("/delete/{id}")
    @ApiOperation(value = "删除角色")
    public R insert(@PathVariable Long id) {
        logger.info("删除角色入参:{}", id);
        return roleService.roleDelete(id);
    }

    /**
     * 角色列表分页
     * @param rolePageDTO
     * @return
     */
    @GetMapping("/list")
    @ApiOperation(value = "角色列表分页")
    public R<PageResultVo<RoleInfoVo>> list(RolePageDTO rolePageDTO) {
        logger.info("角色列表分页入参:{}", rolePageDTO);
        return roleService.roleList(rolePageDTO);
    }
}

